<?php
/*
	Version   :  1.0
	Created   :  20081002
	Modified  :  --
	Author    :  Pablo Larenas
	co-Author :
	Descr     : Controlador "Leasing Companies"
	Changelog :
*/
class LeasingCompaniesController extends AppController
{
	var $name      = 'LeasingCompanies';
	var $helpers    = array('Html','Javascript','Ajax');
	
	function index() {
		$this->layout = 'maintenance';
		$lecArray = array();
		
		if (empty($this->data)) {
			$lecs = $this->LeasingCompany->findAll(null,'*','lec_codigo ASC');
			foreach($lecs as $lec) {
				$temp = array();
				foreach($lec['LeasingCompany'] as $key=>$value) {
					$temp[$key] = $value;
				}
				$lecArray[] = $temp;
			}
			$this->set('leasingCompanies', $lecArray);
		} 
	}
	
	function add($id = null) {
		$this->layout = 'ajax';
		if (!empty($this->data)){
			if ($this->LeasingCompany->save($this->data)){
				$this->redirect('/leasing_companies'); 
			}
		} else {
			$this->set('id', $id);
		}
	}
	
	function edit($id = null) {
		
		$this->layout = 'ajax';
		$this->LeasingCompany->id = $id;
		
		if (empty($this->data)){
			$this->data = $this->LeasingCompany->read();
			$this->set('id', $id);
		}else{
			if ($this->LeasingCompany->save($this->data)){
				//$this->Session->setFlash('Item Editado');
				$this->redirect('/leasing_companies');
			} else {
				$this->Session->setFlash('Error al editar el Item');
			}
		}
	}
	
	function view($id = null) {
		
		$this->layout = 'ajax';
		$this->LeasingCompany->id = $id;
		
		if (empty($this->data)){
			//$this->set('owner', $this->ContainerType->read());
			$this->data = $this->LeasingCompany->read();
			$this->set('id', $id);
		}
	}
	
	function delete($id) {
	
		//$this->layout = 'ajax';
		if ($this->LeasingCompany->del($id)) { 
			$this->set('error', '0');
		} else {
			$this->set('error','1');
		}
		$this->redirect('/container_types');
	
	}
}
?>